package com.four.dailymanage.dish.controller;

import com.four.dailymanage.common.bean.ResponseData;
import com.four.dailymanage.common.controller.BaseController;
import com.four.dailymanage.dish.entity.Dish;
import com.four.dailymanage.dish.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/dish")
public class DishController extends BaseController {
    @Autowired
    DishService dishService;
    @PostMapping("/addDish")
    public ResponseData<Boolean> addDish(@RequestBody Dish dish){
        System.out.println(dish);
        return returnBoolean(dishService.addD(dish));
    }
    @DeleteMapping("/deleteDish/{id}")
    public ResponseData<Boolean> deleteDish(@PathVariable("id")Integer id){
        return returnBoolean(dishService.del(id));
    }
    @DeleteMapping("/deletes")
    public ResponseData<Boolean> deletes(@RequestParam("id")List<Integer> ids){
        return returnBoolean(dishService.delIds(ids));
    }
    @PutMapping("/updateDish")
    public ResponseData<Boolean> updateDish(@RequestBody Dish dish){
        return returnBoolean(dishService.updateD(dish));
    }
    
    @GetMapping("/getDish")
    public  ResponseData<Object> getDish( @RequestParam("pageNum") int pageNum,
                                          @RequestParam("pageSize") int pageSize,
                                          @RequestParam(value = "dishName",required = false) String dishName,
                                          @RequestParam(value = "dishType",required = false) String dishType,
                                          @RequestParam(value = "publish",required = false) String publish,
                                          @RequestParam(value = "publishDt",required = false) String publishDt,
                                          @RequestParam(value = "assignDt",required = false) String assignDt){
        return returnObject(dishService.getPageDish(pageNum, pageSize, dishName, dishType, publish, publishDt, assignDt));

    }

}
